using System.Collections.Generic;
using System.Reflection;

namespace RikMigrations
{
	public static class MigrationManager
	{
		public const string DefaultModuleName = "DEFAULT";

		public static void MigrateTo( Assembly assembly, string module, int? version, DbProvider db )
		{
			var moduleAsArray = ( module == null ) ? null : new[] { module };
			CreateRunner( db, assembly ).MigrateTo( moduleAsArray, version );
		}

		private static MigrationRunner CreateRunner( DbProvider db, Assembly assembly )
		{
			return new MigrationRunner( db, FindAllMigrations( assembly ) );
		}

		public static void UpgradeMax( Assembly assembly, DbProvider db, params string[] moduleNames )
		{
			CreateRunner( db, assembly ).MigrateTo( moduleNames, null );
		}

		public static Dictionary<string, List<MigrationAttribute>> FindAllMigrations( Assembly assembly )
		{
			return new MigrationSearch().Search( assembly );
		}
	}
}